<template>
  <div>
      <p>-----------------------</p>
      <div>
          <h4>1.获取所有图书按钮</h4>
      <button @click="getAllFn">获取图书</button>
      </div>
      <p>---------------------------</p>
      <div>
          <h4>2查询书藉信息</h4>
      <input type="text" placeholder="请输入查询的书藉" v-model="bName">
      <button @click="findFn">搜索</button>
      </div>
<p>---------------</p>
    <div>
      <h4>3. 新增图书信息</h4>
      <div><input type="text" placeholder="书名" v-model="bookObj.bookname"/></div>
      <div><input type="text" placeholder="作者" v-model="bookObj.author"/></div>
      <div><input type="text" placeholder="出版社" v-model="bookObj.publisher"/></div>
    </div>
    <button @click="addFn">点击新增图书</button>
  </div> 
</template>

<script>
import axios from 'axios'
axios.defaults.baseURL = 'http://123.57.109.30:3006'
export default {
    data () {
        return {
            bName:'',
            bookObj:{
                bookname:'',
                author:'',
                publiser:''
            }
        }
    },
    methods: {
         getAllFn(){
            axios({
        method: "get",
        url: "/api/getbooks",

      }).then(function (res) {
        console.log(res);
      });
        },
        findFn(){
               axios({
        method: "get",
        url: "/api/getbooks",
    params:{
        bookname:this.bName
    }
      }).then(function (res) {
        console.log(res);
      });
        },
        addFn(){
            axios({
                url:'/api/addbook',
                method:'POST',
                data : {
                   appkey:'7250d3eb-18e1-41bc-8bb2-11483665535a',
                   ...this.bookObj
                }
            })
        }
    } 
}
</script>

<style>

</style>